package com.itboye.ihomebank.presenter;

import com.itboye.ihomebank.base.BasePresenter;
import com.itboye.ihomebank.base.ICompleteListener;
import com.itboye.ihomebank.bean.JinRongBean;
import com.itboye.ihomebank.bean.ResultEntity;
import com.itboye.ihomebank.interfaces.IJinRong;
import com.itboye.ihomebank.responsitory.JinRongRepository;

import java.util.Observer;

/***
 * @author 递增给Responsitory
 */
public class JinRongPresenter extends BasePresenter implements
        IJinRong<JinRongBean> {
    public static final String indexJinRong_fail = "_indexJinRong_fail";
    public static final String indexJinRong_success = "_indexJinRong_success";
    //p2p列表
    public static final String p2p_query_success = "_p2p_query_success";
    public static final String p2p_query_fail = "_p2p_query_fail";
    public static final String p2p_query02_success = "_p2p_query02_success";
    public static final String p2p_query02_fail = "_p2p_query02_fail";
    //我的投资
    public static final String my_tou_zi_success = "_my_tou_zi_success";
    public static final String my_tou_zi_fail = "_my_tou_zi_fail";
    //投资详情
    public static final String tou_zi_xq_success = "_tou_zi_xq_success";
    public static final String tou_zi_xq_fail = "_tou_zi_xq_fail";

    //投资购买
    public static final String tou_zi_goumai_success = "_tou_zi_goumai_success";
    public static final String tou_zi_goumai_fail = "_tou_zi_goumai_fail";

    //住家宝首页
    public static final String zjb_shouye_success = "_zjb_shouye_success";
    public static final String zjb_shouye_fail = "_zjb_shouye_fail";

    //投资记录
    public static final String touzi_jilu_success = "_touzi_jilu_success";
    public static final String touzi_jilu_fail = "_touzi_jilu_fail";

    //还款计划
    public static final String huan_kuan_success = "_huan_kuan_success";
    public static final String huan_kuan_fail = "_huan_kuan_fail";
    ;


    //租金宝（活期）购买转入
    public static final String zhuan_ru_success = "_zhuan_ru_success";
    public static final String zhuan_ru_fail = "_zhuan_ru_fail";

    //租金宝（活期）购买转出
    public static final String zhuan_chu_success = "_zhuan_chu_success";
    public static final String zhuan_chu_fail = "_zhuan_chu_fail";

    //租金宝（活期）详情
    public static final String financial_xq_success = "_financial_xq_success";
    public static final String financial_xq_fail = "_financial_xq_fail";

    public static final String currentJieKuan_success = "_currentJieKuan_success";
    public static final String currentJieKuan_fail = "_currentJieKuan_fail";

    public static final String jiekuanHistory_success = "_jiekuanHistory_success";
    public static final String jiekuanHistory_fail = "_jiekuanHistory_fail";

    public static final String huanKuanDetail_success = "_huanKuanDetail_success";
    public static final String huanKuanDetail_fail = "_huanKuanDetail_fail";
    public static final String sendJinRongPay_success = "_sendJinRongPay_success";
    public static final String sendJinRongPay_fail = "_sendJinRongPay_fail";

    //回款计划
    public static final String huikuan_success = "_huikuan_success";
    public static final String huikuan_fail = "_huikuan_fail";

    //发布转让
    public static final String zhuanrang_success = "_huikuan_success";
    public static final String zhuanrang_fail = "_huikuan_fail";

    //设置通讯录
    public static final String tongxunlu_success = "_tongxunlu_success";
    public static final String tongxunlu_fail = "_tongxunlu_fail";

    public JinRongPresenter(Observer observer) {
        super(observer);
    }


    @Override
    public void listP2p(String current_page, String per_page, String b_status, String dt_type, String order) {
        IJinRong<JinRongBean> user = new JinRongRepository(
                new ICompleteListener() {

                    @Override
                    public void success(ResultEntity result) {
                        result.setEventTag(Tag_Success);
                        result.setEventType(p2p_query_success);
                        setChanged();
                        notifyObservers(result);
                    }

                    @Override
                    public void failure(ResultEntity result) {
                        result.setEventTag(Tag_Success);
                        result.setEventType(p2p_query_fail);
                        setChanged();
                        notifyObservers(result);

                    }
                });
        user.listP2p(current_page, per_page, b_status, dt_type, order);
    }

    @Override
    public void listP2p02(String current_page, String per_page, String b_status, String dt_type, String order) {
        IJinRong<JinRongBean> user = new JinRongRepository(
                new ICompleteListener() {

                    @Override
                    public void success(ResultEntity result) {
                        result.setEventTag(Tag_Success);
                        result.setEventType(p2p_query02_success);
                        setChanged();
                        notifyObservers(result);
                    }

                    @Override
                    public void failure(ResultEntity result) {
                        result.setEventTag(Tag_Success);
                        result.setEventType(p2p_query02_fail);
                        setChanged();
                        notifyObservers(result);

                    }
                });
        user.listP2p02(current_page, per_page, b_status, dt_type, order);
    }

    @Override
    public void detailP2p(String id) {
        IJinRong<JinRongBean> user = new JinRongRepository(
                new ICompleteListener() {

                    @Override
                    public void success(ResultEntity result) {
                        result.setEventTag(Tag_Success);
                        result.setEventType(tou_zi_xq_success);
                        setChanged();
                        notifyObservers(result);
                    }

                    @Override
                    public void failure(ResultEntity result) {
                        result.setEventTag(Tag_Success);
                        result.setEventType(tou_zi_xq_fail);
                        setChanged();
                        notifyObservers(result);

                    }
                });
        user.detailP2p(id);
    }

    @Override
    public void indexJinRong(String uid) {
        IJinRong<JinRongBean> user = new JinRongRepository(
                new ICompleteListener() {

                    @Override
                    public void success(ResultEntity result) {
                        result.setEventTag(Tag_Success);
                        result.setEventType(indexJinRong_success);
                        setChanged();
                        notifyObservers(result);
                    }

                    @Override
                    public void failure(ResultEntity result) {
                        result.setEventTag(Tag_Success);
                        result.setEventType(indexJinRong_fail);
                        setChanged();
                        notifyObservers(result);

                    }
                });
        user.indexJinRong(uid);
    }

    @Override
    public void onMyTouZhi(String uid, String current_page, String per_page, String status) {
        IJinRong<JinRongBean> user = new JinRongRepository(
                new ICompleteListener() {

                    @Override
                    public void success(ResultEntity result) {
                        result.setEventTag(Tag_Success);
                        result.setEventType(my_tou_zi_success);
                        setChanged();
                        notifyObservers(result);
                    }

                    @Override
                    public void failure(ResultEntity result) {
                        result.setEventTag(Tag_Success);
                        result.setEventType(my_tou_zi_fail);
                        setChanged();
                        notifyObservers(result);

                    }
                });
        user.onMyTouZhi(uid, current_page, per_page, status);
    }

    @Override
    public void myGoumai(String uid, String id, String money) {
        IJinRong<JinRongBean> user = new JinRongRepository(
                new ICompleteListener() {

                    @Override
                    public void success(ResultEntity result) {
                        result.setEventTag(Tag_Success);
                        result.setEventType(tou_zi_goumai_success);
                        setChanged();
                        notifyObservers(result);
                    }

                    @Override
                    public void failure(ResultEntity result) {
                        result.setEventTag(Tag_Success);
                        result.setEventType(tou_zi_goumai_fail);
                        setChanged();
                        notifyObservers(result);

                    }
                });
        user.myGoumai(uid, id, money);
    }

    /**
     * 住家宝首页
     *
     * @param size
     */
    @Override
    public void zjbShouYe(String size) {
        IJinRong<JinRongBean> user = new JinRongRepository(
                new ICompleteListener() {

                    @Override
                    public void success(ResultEntity result) {
                        result.setEventTag(Tag_Success);
                        result.setEventType(zjb_shouye_success);
                        setChanged();
                        notifyObservers(result);
                    }

                    @Override
                    public void failure(ResultEntity result) {
                        result.setEventTag(Tag_Success);
                        result.setEventType(zjb_shouye_fail);
                        setChanged();
                        notifyObservers(result);

                    }
                });
        user.zjbShouYe(size);
    }

    @Override
    public void touZiJiLu(String id) {
        IJinRong<JinRongBean> user = new JinRongRepository(
                new ICompleteListener() {

                    @Override
                    public void success(ResultEntity result) {
                        result.setEventTag(Tag_Success);
                        result.setEventType(touzi_jilu_success);
                        setChanged();
                        notifyObservers(result);
                    }

                    @Override
                    public void failure(ResultEntity result) {
                        result.setEventTag(Tag_Success);
                        result.setEventType(touzi_jilu_fail);
                        setChanged();
                        notifyObservers(result);
                    }
                });
        user.touZiJiLu(id);
    }

    @Override
    public void onBenJinLiXi(String rate_year, String money, String month,String day, String pay_type, String start_time) {
        IJinRong<JinRongBean> user = new JinRongRepository(
                new ICompleteListener() {

                    @Override
                    public void success(ResultEntity result) {
                        result.setEventTag(Tag_Success);
                        result.setEventType(huan_kuan_success);
                        setChanged();
                        notifyObservers(result);
                    }

                    @Override
                    public void failure(ResultEntity result) {
                        result.setEventTag(Tag_Success);
                        result.setEventType(huan_kuan_fail);
                        setChanged();
                        notifyObservers(result);
                    }
                });
        user.onBenJinLiXi(rate_year, money, month, day,pay_type, start_time);
    }

    @Override
    public void onHuiKuan(String uid, String id) {
        IJinRong<JinRongBean> user = new JinRongRepository(
                new ICompleteListener() {

                    @Override
                    public void success(ResultEntity result) {
                        result.setEventTag(Tag_Success);
                        result.setEventType(huikuan_success);
                        setChanged();
                        notifyObservers(result);
                    }

                    @Override
                    public void failure(ResultEntity result) {
                        result.setEventTag(Tag_Success);
                        result.setEventType(huikuan_fail);
                        setChanged();
                        notifyObservers(result);
                    }
                });
        user.onHuiKuan(uid, id);
    }

    /**
     * 租金宝购买转入
     *
     * @param uid
     * @param id
     * @param money
     */
    @Override
    public void onZhuanRu(String uid, String id, String money) {
        IJinRong<JinRongBean> user = new JinRongRepository(
                new ICompleteListener() {

                    @Override
                    public void success(ResultEntity result) {
                        result.setEventTag(Tag_Success);
                        result.setEventType(zhuan_ru_success);
                        setChanged();
                        notifyObservers(result);
                    }

                    @Override
                    public void failure(ResultEntity result) {
                        result.setEventTag(Tag_Error);
                        result.setEventType(zhuan_ru_fail);
                        setChanged();
                        notifyObservers(result);
                    }
                });
        user.onZhuanRu(uid, id, money);
    }

    /**
     * 租金宝购买转出
     *
     * @param uid
     * @param id
     * @param money
     */
    @Override
    public void onZhuanChu(String uid, String id, String money) {
        IJinRong<JinRongBean> user = new JinRongRepository(
                new ICompleteListener() {

                    @Override
                    public void success(ResultEntity result) {
                        result.setEventTag(Tag_Success);
                        result.setEventType(zhuan_chu_success);
                        setChanged();
                        notifyObservers(result);
                    }

                    @Override
                    public void failure(ResultEntity result) {
                        result.setEventTag(Tag_Error);
                        result.setEventType(zhuan_chu_fail);
                        setChanged();
                        notifyObservers(result);
                    }
                });
        user.onZhuanChu(uid, id, money);
    }

    /**
     * 租金包（活期）详情
     *
     * @param id
     * @param uid
     */
    @Override
    public void onXiangQing(String id, String uid) {
        IJinRong<JinRongBean> user = new JinRongRepository(
                new ICompleteListener() {

                    @Override
                    public void success(ResultEntity result) {
                        result.setEventTag(Tag_Success);
                        result.setEventType(financial_xq_success);
                        setChanged();
                        notifyObservers(result);
                    }

                    @Override
                    public void failure(ResultEntity result) {
                        result.setEventTag(Tag_Success);
                        result.setEventType(financial_xq_fail);
                        setChanged();
                        notifyObservers(result);
                    }
                });
        user.onXiangQing(id, uid);
    }

    @Override
    public void currentJieKuan(String uid) {
        IJinRong<JinRongBean> user = new JinRongRepository(
                new ICompleteListener() {

                    @Override
                    public void success(ResultEntity result) {
                        result.setEventTag(Tag_Success);
                        result.setEventType(currentJieKuan_success);
                        setChanged();
                        notifyObservers(result);
                    }

                    @Override
                    public void failure(ResultEntity result) {
                        result.setEventTag(Tag_Success);
                        result.setEventType(currentJieKuan_fail);
                        setChanged();
                        notifyObservers(result);
                    }
                });
        user.currentJieKuan(uid);
    }

    @Override
    public void jiekuanHistory(String uid, String current_page, String per_page) {
        IJinRong<JinRongBean> user = new JinRongRepository(
                new ICompleteListener() {

                    @Override
                    public void success(ResultEntity result) {
                        result.setEventTag(Tag_Success);
                        result.setEventType(jiekuanHistory_success);
                        setChanged();
                        notifyObservers(result);
                    }

                    @Override
                    public void failure(ResultEntity result) {
                        result.setEventTag(Tag_Success);
                        result.setEventType(jiekuanHistory_fail);
                        setChanged();
                        notifyObservers(result);
                    }
                });
        user.jiekuanHistory(uid, current_page, per_page);
    }

    @Override
    public void huanKuanDetail(String sp, String id) {
        IJinRong<JinRongBean> user = new JinRongRepository(
                new ICompleteListener() {

                    @Override
                    public void success(ResultEntity result) {
                        result.setEventTag(Tag_Success);
                        result.setEventType(huanKuanDetail_success);
                        setChanged();
                        notifyObservers(result);
                    }

                    @Override
                    public void failure(ResultEntity result) {
                        result.setEventTag(Tag_Success);
                        result.setEventType(huanKuanDetail_fail);
                        setChanged();
                        notifyObservers(result);
                    }
                });
        user.huanKuanDetail(sp, id);
    }

    @Override
    public void sendJinRongPay(String uid, String pay_code_type, int items, String pay_type, String wallet_pay_money, String wallet_only, String amount) {
        IJinRong<JinRongBean> user = new JinRongRepository(
                new ICompleteListener() {

                    @Override
                    public void success(ResultEntity result) {
                        result.setEventTag(Tag_Success);
                        result.setEventType(sendJinRongPay_success);
                        setChanged();
                        notifyObservers(result);
                    }

                    @Override
                    public void failure(ResultEntity result) {
                        result.setEventTag(Tag_Success);
                        result.setEventType(sendJinRongPay_fail);
                        setChanged();
                        notifyObservers(result);
                    }
                });
        user.sendJinRongPay(uid, pay_code_type, items, pay_type, wallet_pay_money, wallet_only, amount);
    }

    @Override
    public void fabuZhuangRang(String id, String uid) {
        IJinRong<JinRongBean> user = new JinRongRepository(
                new ICompleteListener() {

                    @Override
                    public void success(ResultEntity result) {
                        result.setEventTag(Tag_Success);
                        result.setEventType(zhuanrang_success);
                        setChanged();
                        notifyObservers(result);
                    }

                    @Override
                    public void failure(ResultEntity result) {
                        result.setEventTag(Tag_Success);
                        result.setEventType(zhuanrang_fail);
                        setChanged();
                        notifyObservers(result);
                    }
                });
        user.fabuZhuangRang(id, uid);
    }

    @Override
    public void tongXunLu(String uid, String address) {
        IJinRong<JinRongBean> user = new JinRongRepository(
                new ICompleteListener() {

                    @Override
                    public void success(ResultEntity result) {
                        result.setEventTag(Tag_Success);
                        result.setEventType(tongxunlu_success);
                        setChanged();
                        notifyObservers(result);
                    }

                    @Override
                    public void failure(ResultEntity result) {
                        result.setEventTag(Tag_Success);
                        result.setEventType(tongxunlu_fail);
                        setChanged();
                        notifyObservers(result);
                    }
                });
        user.tongXunLu(uid, address);
    }
}
